<!--
 * @Author: ChunLai
 * @Date: 2023-10-12 11:57:15
 * @LastEditTime: 2025-08-12 17:51:35
 * @Description: 条款文档综合列表页
 * @FilePath: \02.bldinsure\src\views\multipages\colligate.vue
-->
<template>
  <div>
    <div class="file_list_title">{{ pageTitle }}</div>
    <div class="file_list">
      <div
        class="file_item btm_line"
        v-for="(item, index) in fileList"
        :key="`${item.productNo}${index}`"
        @click="goReadPage(item)"
      >
        <span class="txt">
          {{ getFileName(item.fileName) }}
        </span>
        <div class="icons">
          <span class="ms-row-icon"></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "ColligateClausePage",
  data() {
    return {
      type: "tk",
    };
  },
  components: {},
  computed: {
    ...mapGetters({
      planModule: "home/planModule",
      colligateFiles: "page/colligateFiles",
      comClauseList: "page/comClauseList",
      apiClauseList: "home/apiClauseList",
    }),
    insureFilesList() {
      let res = [];
      if (this.comClauseList.length > 0) {
        res = [...this.comClauseList];
      }
      if (this.apiClauseList.length > 0) {
        res = [...res, ...this.apiClauseList];
      }
      return res;
    },
    pageTitle() {
      let res = "";
      const obj = this.colligateFiles.find((ele) => ele.value == this.type);
      if (obj) {
        res = obj.fileName;
      }
      return res;
    },
    typeKey() {
      let res = "";
      const obj = this.colligateFiles.find((ele) => ele.value == this.type);
      if (obj) {
        res = obj.keyword;
      }
      return res;
    },
    fileList() {
      let res = [];
      if (this.insureFilesList.length > 0) {
        res = this.insureFilesList.filter((ele) => {
          if (this.type === "tk") {
            if (
              ele.fileName.indexOf(this.typeKey) != -1 &&
              ele.fileName.indexOf("产品说明书") == -1 &&
              ele.fileName.indexOf("免除") == -1 &&
              ele.fileName.indexOf("费率") == -1
            ) {
              return ele;
            }
          } else {
            if (ele.fileName.indexOf(this.typeKey) != -1) {
              return ele;
            }
          }
        });
      }
      return res;
    },
  },
  watch: {},
  created() {
    const querys = this.$route.query;
    if (querys.type) {
      this.type = querys.type;
    }
  },
  mounted() {},
  methods: {
    goReadPage(item) {
      if (!item.fileUrl) return this.$toast("未查询到文件");
      // 使用新版PDF展示页
      this.$router.push(`/read?ftype=${item.suffixType}&fid=${item.id}`);
    },
    getFileName(fileName) {
      let res = "";
      res = fileName.replace("《", "").replace("》", "");
      return res;
    },
  },
};
</script>

<style lang="less" scoped>
.file_list_title {
  height: 50px;
  line-height: 50px;
  color: #666;
  font-size: 14px;
  font-weight: 400;
  padding-left: 10px;
  background-color: #f5f7fa;
}
.file_list {
  background-color: #fff;
  .file_item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    color: #333;
    font-size: 16px;
    .txt {
      flex: 1;
      font-size: 14px;
      line-height: 18px;
    }
    .icons {
      display: flex;
      justify-content: flex-end;
      width: 70px;
      line-height: 18px;
      height: fit-content;
    }
  }
}
</style>
